/**
 * creation: 22-apr-2008
 */
package org.jfonia.structure;

import org.jfonia.connect.Callable;
import org.jfonia.connect.Value;
import org.jfonia.connect.logic.IntLessThan;
import org.jfonia.connect.logic.IntLessThanOrEqual;
import org.jfonia.connect.logic.LogicalAnd;
import org.jfonia.connect.logic.While;

/**
 * @author wijnand.schepens@gmail.com
 *
 */
public class ForwardTo
{
	public static Callable createForwardTo(IntIterator it, Value<Integer> targetValue)
	{
		return new While(new LogicalAnd(it.getProceedCondition(), 
				                        new IntLessThanOrEqual(it.getLookaheadValue(), 
				                        		               targetValue) ), 
				         it.getProceeder());
	}
	
	public static Callable createForwardTo(Slice slice, String refId, Value<Integer> targetValue)
	{
		return new While(createForwardCondition(slice, refId, targetValue), slice.getProceeder() );
	}
	
	public static Value<Boolean> createForwardCondition(Slice slice, String refId, Value<Integer> targetValue)
	{
		return new LogicalAnd(slice.getProceedCondition(), 
				              new IntLessThanOrEqual(slice.getLookaheadProperty(refId), targetValue) ); 
	}
	
}
